package com.foxzzz.dynamic.programming;

public class Solution198 {
    public static void main(String[] args) {

        System.out.println(new Solution198().rob(new int[]{2,7,9,3}));

    }


    public int rob(int[] nums) {
        if(nums.length==0)
            return 0;
        else if(nums.length==1)
            return nums[0];


        int[] dp=new int[nums.length];
        for (int i = 0; i < nums.length; i++) {
            dp[i]=Math.max(i-2<0?0:dp[i-2],i-3<0?0:dp[i-3])+nums[i];
        }

        return dp[dp.length-1]>dp[dp.length-2]?dp[dp.length-1]:dp[dp.length-2];
    }
}
